package code.c12;

/**
 * @author thinkpad - 83start
 * @version v1.0
 * @create 2022/11/24 11:13
 * @package code.c12
 * @description Thread 实现多线程
 */

public class TestThread {
    public static void main(String[] args) throws InterruptedException {
        // 执行分线程
        MyThread testThread1 = new MyThread();
        testThread1.setName("测试线程1");
        testThread1.start();

        MyThread testThread2 = new MyThread();
        testThread2.setName("测试线程2");
        testThread2.start();

        // 输出当前线程的名称
        for (int i = 0; i < 10; i++) {
            // 线程休眠
            Thread.sleep(500);
            System.out.println(Thread.currentThread().getName());
        }

    }
}

class MyThread extends Thread {
    @Override
    public void run() {
        // 输出当前线程的名称
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName());
        }
    }
}
